package com.qipay.baas.mapper;

import com.qipay.baas.model.CpWithdrawTradlog;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface CpWithdrawTradlogMapper {
    @Delete({
        "delete from cp_withdraw_tradlog",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into cp_withdraw_tradlog (cp_id, amount, ",
        "fee, actual_amount, ",
        "`type`, card_bank, ",
        "card_sub_bank, card_bank_no, ",
        "card_no, id_card_no, ",
        "`name`, mobile, trade_no, ",
        "out_trade_no, attach, ",
        "remark, `state`, `operation`, ",
        "province, `city`, `area`, is_company,",
        "create_time, finish_time)",
        "values (#{cpId,jdbcType=BIGINT}, #{amount,jdbcType=INTEGER}, ",
        "#{fee,jdbcType=DECIMAL}, #{actualAmount,jdbcType=INTEGER}, ",
        "#{type,jdbcType=TINYINT}, #{cardBank,jdbcType=VARCHAR}, ",
        "#{cardSubBank,jdbcType=VARCHAR}, #{cardBankNo,jdbcType=VARCHAR}, ",
        "#{cardNo,jdbcType=VARCHAR}, #{idCardNo,jdbcType=VARCHAR}, ",
        "#{name,jdbcType=VARCHAR}, #{mobile,jdbcType=VARCHAR}, #{tradeNo,jdbcType=VARCHAR}, ",
        "#{outTradeNo,jdbcType=VARCHAR}, #{attach,jdbcType=VARCHAR}, ",
        "#{remark,jdbcType=VARCHAR}, #{state,jdbcType=TINYINT}, #{operation,jdbcType=TINYINT}, ",
        "#{province,jdbcType=VARCHAR}, #{city,jdbcType=VARCHAR}, #{area,jdbcType=VARCHAR}, #{isCompany,jdbcType=VARCHAR},",
        "#{createTime,jdbcType=TIMESTAMP}, #{finishTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insert(CpWithdrawTradlog record);

    @InsertProvider(type=CpWithdrawTradlogSqlProvider.class, method="insertSelective")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insertSelective(CpWithdrawTradlog record);

    @Select({
        "select",
        "id, cp_id, amount, fee, actual_amount, `type`, card_bank, card_sub_bank, card_bank_no, ",
        "card_no, id_card_no, `name`, mobile, trade_no, out_trade_no, attach, remark,",
        "`state`, `operation`, create_time, finish_time,`province`,`city`,`area`,is_company",
        "from cp_withdraw_tradlog",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="cp_id", property="cpId", jdbcType=JdbcType.BIGINT),
        @Result(column="amount", property="amount", jdbcType=JdbcType.INTEGER),
        @Result(column="fee", property="fee", jdbcType=JdbcType.DECIMAL),
        @Result(column="actual_amount", property="actualAmount", jdbcType=JdbcType.INTEGER),
        @Result(column="type", property="type", jdbcType=JdbcType.TINYINT),
        @Result(column="card_bank", property="cardBank", jdbcType=JdbcType.VARCHAR),
        @Result(column="card_sub_bank", property="cardSubBank", jdbcType=JdbcType.VARCHAR),
        @Result(column="card_bank_no", property="cardBankNo", jdbcType=JdbcType.VARCHAR),
        @Result(column="card_no", property="cardNo", jdbcType=JdbcType.VARCHAR),
        @Result(column="id_card_no", property="idCardNo", jdbcType=JdbcType.VARCHAR),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="mobile", property="mobile", jdbcType=JdbcType.VARCHAR),
        @Result(column="trade_no", property="tradeNo", jdbcType=JdbcType.VARCHAR),
        @Result(column="out_trade_no", property="outTradeNo", jdbcType=JdbcType.VARCHAR),
        @Result(column="attach", property="attach", jdbcType=JdbcType.VARCHAR),
        @Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR),
        @Result(column="province", property="province", jdbcType=JdbcType.VARCHAR),
        @Result(column="city", property="city", jdbcType=JdbcType.VARCHAR),
        @Result(column="area", property="area", jdbcType=JdbcType.VARCHAR),
        @Result(column="is_company", property="isCompany", jdbcType=JdbcType.VARCHAR),
        @Result(column="state", property="state", jdbcType=JdbcType.TINYINT),
        @Result(column="operation", property="operation", jdbcType=JdbcType.TINYINT),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="finish_time", property="finishTime", jdbcType=JdbcType.TIMESTAMP)
    })
    CpWithdrawTradlog selectByPrimaryKey(Long id);

    @UpdateProvider(type=CpWithdrawTradlogSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(CpWithdrawTradlog record);

    @Update({
        "update cp_withdraw_tradlog",
        "set cp_id = #{cpId,jdbcType=BIGINT},",
          "amount = #{amount,jdbcType=INTEGER},",
          "fee = #{fee,jdbcType=DECIMAL},",
          "actual_amount = #{actualAmount,jdbcType=INTEGER},",
          "`type` = #{type,jdbcType=TINYINT},",
          "card_bank = #{cardBank,jdbcType=VARCHAR},",
          "card_sub_bank = #{cardSubBank,jdbcType=VARCHAR},",
          "card_bank_no = #{cardBankNo,jdbcType=VARCHAR},",
          "card_no = #{cardNo,jdbcType=VARCHAR},",
          "id_card_no = #{idCardNo,jdbcType=VARCHAR},",
          "`name` = #{name,jdbcType=VARCHAR},",
          "mobile = #{mobile,jdbcType=VARCHAR},",
          "trade_no = #{tradeNo,jdbcType=VARCHAR},",
          "out_trade_no = #{outTradeNo,jdbcType=VARCHAR},",
          "attach = #{attach,jdbcType=VARCHAR},",
          "remark = #{remark,jdbcType=VARCHAR},",
          "province = #{province,jdbcType=VARCHAR},",
          "city = #{city,jdbcType=VARCHAR},",
          "area = #{area,jdbcType=VARCHAR},",
          "`state` = #{state,jdbcType=TINYINT},",
          "`operation` = #{operation,jdbcType=TINYINT},",
          "create_time = #{createTime,jdbcType=TIMESTAMP},",
          "finish_time = #{finishTime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(CpWithdrawTradlog record);
}